<template>
  <div class="mine">
    <div class="user_info">
      <!-- 用户信息 -->
      <img :src="img" alt />
      <div class="user_detail">
        <h4>{{name}}</h4>
      </div>
      <div class="xiaoqi">
        <span>{{xiaoname}}</span>
      </div>
    </div>
    <div class="order_info">
      <orderCell
        icon="https://hterobot-kimage.oss-cn-qingdao.aliyuncs.com/images/personal_changephoto@2x.png"
        title="更换头像"
        @click="handleavter"
      ></orderCell>
      <orderCell
        icon="https://hterobot-kimage.oss-cn-qingdao.aliyuncs.com/images/personal_changePWD@2x.png"
        title="修改密码"
        @click="handlemima"
      ></orderCell>
    </div>
    <div class="order_info">
      <orderCell
        icon="https://hterobot-kimage.oss-cn-qingdao.aliyuncs.com/images/personal_aboutUS@2x.png"
        title="关于"
        @click="handleCell"
      ></orderCell>
    </div>
    <button @click="btn_click" class="qs_btn">退出登录</button>
  </div>
</template>
<script>
import orderCell from "../../components/orderCell/index";
export default {
  data() {
    return {
      img: "",
      name: "",
      hotLessons: "",
      images: "",
      xiaoname:""
    };
  },
  onload() {
  },
  mounted() {
    this.start();
  },
  methods: {
    start() {
      const jihe = wx.getStorageSync("loginUserInfo");
      this.img = jihe.headimg;
      this.name = jihe.name;
      var that = this
      const ID=jihe.schooladdressid
      wx.request({
        url: this.$interfaces.addressid+"/"+ID,
        method: "get",
        success: function(res) {
           that.xiaoname=res.data.name;
        }
      });
    },
    handleCell() {
      wx.navigateTo({
        url: "../counter/main"
      });
    },
    handleavter() {
      this.$https
        .request({
          url: this.$interfaces.oss,
          method: "get"
        })
        .then(res => {
          console.log(res)
          this.hotLessons = res;
        });

      var that = this;
      wx.showActionSheet({
        itemList: ["从手机相册选择", "拍照"],
        success: function(res) {
          if (res.tapIndex === 0) {
            wx.chooseImage({
              count: 1, // 设置最多三张
              sizeType: ["original", "compressed"],
              sourceType: ["album", 'camera'],
              async success(unt) {

                // console.log(res)
                // var tempFilePaths = res.tempFilePaths;
                // // console.log(res.tempFilePaths[0])
                // that.images = res.tempFilePaths[0];
                // // console.log(that.images)
                // // console.log(res)
                // // console.log(that.hotLessons.data)
                // // console.log(res.tempFilePaths)
                // // console.log(res)

                // var client = new OSS({
                //   region: "oss-cn-qingdao",
                //   accessKeyId: that.hotLessons.data.accessKeyId,
                //   accessKeySecret: that.hotLessons.data.accessKeySecret,
                //   stsToken: that.hotLessons.data.securityToken,
                //   bucket: "cdn-hterobot"
                // });
                // var id = uuid();
                // // var token = e.type.split("/")[1];
                // var file = await client.put(
                //   "xcx/" + id + "." + 'png',
                //   res.tempFiles[0]
                // );
                //   console.log(file);
                // return true;
                // console.log(client)
                // 图片预览
                // wx.previewImage({
                //   current: res.tempFilePaths[0],
                //   urls: res.tempFilePaths
                // });
              }
            });
          } else if (res.tapIndex === 1) {
            wx.chooseImage({
              count: 1, // 设置最多三张
              sizeType: ["original", "compressed"],
              sourceType: ["camera"],
              success(res) {
                var tempFilePaths = res.tempFilePaths;
                // console.log(res.tempFilePaths[0])
                // 图片预览
                // wx.previewImage({
                //   current: res.tempFilePaths[0],
                //   urls: res.tempFilePaths
                // });
              }
            });
          }
        },
        fail: function(res) {
          // console.log(res.errMsg);
        }
      });
    },
    handlemima() {
      wx.navigateTo({
        url: "../yuanpass/main"
      });
    },
    //退出按钮
    btn_click() {
      console.log(123);
      wx.clearStorage();
      wx.reLaunch({
        url: "../home/main"
      });
    }
  },
  computed: {
    user() {
      // console.log(this.$store.getters.user);
      return this.$store.getters.user;
    },
    lessonInfo() {
      // console.log(this.$store.getters.lessonInfo);
      return this.$store.getters.lessonInfo;
    }
  },
  components: {
    orderCell
  }
};
</script>
<style>
.user_info {
  background-color: #fff;
  padding: 8px 16px;
  box-sizing: border-box;
  border-bottom: 1px solid #ebeef5;
  border-top: 1px solid #ebeef5;
  display: flex;
  flex-direction: row;
}
.user_info img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-right: 20px;
}
.user_detail h4 {
  margin: 82rpx 0;
  font-weight: bold;
}
.user_detail {
  flex: 1;
}
.xiaoqi {
  flex: 1;
  margin: 82rpx 0;
  color: #aaa;
  font-size: 14px;
}
.learn_info {
  padding: 10px 16px;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  background-color: #fff;
  border-bottom: 1px solid #ebeef5;
}
.learn_info .learn_detail {
  text-align: center;
  flex: 1;
}
.learn_detail span {
  color: #aaa;
  font-size: 14px;
}

.order_info {
  margin-top: 16px;
}
.qs_btn {
  position: absolute;
  top: 90%;
  left: 10%;
  width: 80%;
  background: red;
  color: #fff;
  border-radius: 5px;
}
</style>
